﻿using IceZero.DataStore;
using IceZero.DataStore.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;

namespace IceZero.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class UserGroupController : ControllerBase
    {
        private readonly UserGroupDataStore _userGroupDataStore;
        public UserGroupController(UserGroupDataStore userGroupDataStore)
        {
            _userGroupDataStore = userGroupDataStore;
        }

        [HttpGet("GetUserGroupList")]
        public List<UserGroup> GetUserGroupList()
        {
            return _userGroupDataStore.QueryAll();
        }

        [HttpPost("AddUserGroup")]
        public void AddUser(UserGroup userGroup)
        {
            _userGroupDataStore.Save(userGroup);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        [HttpPost("DeleteUser")]
        public void DeleteUser(string guid)
        {
            var userGroup = _userGroupDataStore.QueryById(guid);
            if (userGroup == null)
            {
                return;
            }
            _userGroupDataStore.Delete(userGroup);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        [HttpPost("/api/test/[controller]/AddMockUserGroup")]
        public IEnumerable<UserGroup> AddMockUserGroup(int count)
        {
            var list = new LinkedList<UserGroup>();

            for (int i = 0; i < count; i++)
            {
                var userGroup = new UserGroup()
                {
                    CreateTime=DateTime.Now,
                    Name="Group"+i
                };
                _userGroupDataStore.Save(userGroup);
                list.AddLast(userGroup);
            }
            return list;
        }
    }
}
